package com.kedacom.ctsp.config;

import com.kedacom.ctsp.authz.security.AuthzSecurityProperties;
import com.kedacom.ctsp.authz.security.AuthzWebSecurityConfigurerAdapter;
import feign.Request;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.web.client.RestTemplate;

@Configuration
public class ExampleWebSecurityConfiguration extends AuthzWebSecurityConfigurerAdapter {


    @Autowired
    private AuthzSecurityProperties securityProperties;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        super.configure(http);
        http.formLogin().loginPage(securityProperties.getClientLoginUrl());
    }

    @Bean
    public RestTemplate restTemplate() {

        //restTemplate 设置超时
        SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();
        simpleClientHttpRequestFactory.setConnectTimeout(30000);
        simpleClientHttpRequestFactory.setReadTimeout(30000);
        return new RestTemplate(simpleClientHttpRequestFactory);
    }
//    @Bean
//    Request.Options feignOptions() {
//        return new Request.Options(/**connectTimeoutMillis**/100 * 1000, /** readTimeoutMillis **/100 * 1000);
//    }
}
